/*
 * Description: Extracts all the information from the files -alumnos & columnas-
 */

package exampleseverything.logic;

import java.util.List;
import java.util.LinkedList;
import exampleseverything.beans.Alumno;
import exampleseverything.beans.Columna;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
/**
 *
 * @author HellCoders
 */
public class DataExtractor {
    
    /**
     * this method gets all tha available alumnos from the alumnos.txt
     * and returns a List with all the data.
     * @param file
     * @return alumnos List
     * @throws IOException
     */
    public static List<Alumno> getAlumnos(String file)throws IOException {
        List<Alumno> alumnos = new LinkedList<Alumno>();
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line = br.readLine();
        while(line != null) {
            String[] als = line.split("-");
            Alumno al = new Alumno(Integer.parseInt(als[0]),als[1],als[2],als[3],Integer.parseInt(als[4]),als[5],Integer.parseInt(als[6]));
            alumnos.add(al);
            line = br.readLine();
        }
        br.close();
        return alumnos;
    }

    /**
     * This method gets the column names and descriptioins from the
     * columnas.txt
     * @param file
     * @return A column/description List
     * @throws IOException
     */
    public static List<Columna> getColumnas(String file)throws IOException{
        List<Columna> columnas = new LinkedList<Columna>();
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line = br.readLine();
        while(line != null) {
            String[] cols = line.split("-");
            Columna col = new Columna(cols[1],cols[0]);
            columnas.add(col);
            line = br.readLine();
        }
        br.close();
        return columnas;
    }
}
